package org.tomcat.unit502;

public final class Bootstrap {

    public static void main(String[] args) {
        HttpConnector connector = new HttpConnector();
        SimpleWrapper wrapper1 = new SimpleWrapper();
        wrapper1.setName("Primitive");
        wrapper1.setServletClass("org.tomcat.unit502.PrimitiveServlet");
        Wrapper wrapper2 = new SimpleWrapper();
        wrapper2.setName("Modern");
        wrapper2.setServletClass("org.tomcat.unit502.ModernServlet");

        Context context = new SimpleContext();
        context.addChild(wrapper1);
        context.addChild(wrapper2);

        Valve valve1 = new ClientIPLoggerValve();
        Valve valve2 = new HeaderLoggerValve();
        context.addValve(valve1);
        context.addValve(valve2);

        Mapper mapper = new SimpleContextMapper();
        mapper.setProtocol("http");
        mapper.setContainer(context);
        context.addMapper(mapper);

        Loader loader = new SimpleLoader();
        context.setLoader(loader);
        context.addServletMapping("/PrimitiveServlet", "Primitive");
        context.addServletMapping("/ModernServlet", "Modern");
        connector.setContainer(context);

        try {
            connector.initialize();
            connector.start();

            System.in.read();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
